#!/bin/bash

c_num=${1:-10}
docker_image="ssdp_demo:latest"
network=pub_net

c_ids=$(docker ps -a | awk -v var="$docker_image" 'NR>1 && $2==var {print $1}')
if [ -n "$c_ids" ]; then
    echo 'delete existing docker containers ...'
    docker rm -f $c_ids >> /dev/null
fi

node_id=2
for ((i=0; i<$c_num; i++)); do
    c_ip="192.168.0.$node_id"
    nohup docker run -d --rm --name node_$node_id --network $network --ip $c_ip $docker_image 1>/dev/null 2>&1  &
    ((node_id++))
done

echo 'done'

